package com.itheima.edu.info.manager.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public final class Age {
    private Age() {
    }

    public static int getAgeByBirthday(String bir) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date birTime = sdf.parse(bir);
            Date date = new Date();
            long time1 = date.getTime();
            long time2 = birTime.getTime();
            long l = (time1 - time2) / (1000L * 3600 * 24 * 365);
            return (int) l;
        } catch (ParseException e) {
           e.printStackTrace();
        }
        return 0;
    }


}
